#pragma once
#include "BaseGameEntity.h"
#include "state\statemachine.h"
#include "..\DXG\DXViewEntity.h"
#include "..\DXG\DXMesh.h"
#include "..\GWorld\Map.h"
#include "..\GItem\ThinkingView.h"

enum Locations;

class Miner :
	public BaseGameEntity, public DXViewEntity
{
// Graphic
private:
	static DXMesh s_mesh;

public:
	static HRESULT CreateMesh(LPDIRECT3DDEVICE9 pd3ddev9);

	virtual HRESULT Draw(LPDIRECT3DDEVICE9 pd3ddev9)
	{
		pd3ddev9->SetTransform(D3DTS_WORLD, &m_world);
		s_mesh.Draw(pd3ddev9);
		// Thinks
		return m_ThinkingView.Draw(pd3ddev9);
	}

	void SetPos(D3DXVECTOR3 pos)
	{
		D3DXMatrixTranslation(&m_world, pos.x, pos.y + 2.5f, pos.z);
	}

// Motion
private:
	ThinkingView m_ThinkingView;

	POINTU m_Position;

	POINTU m_NextPosition;

	POINTU m_TargetPosition;

	const float m_fTopSpeed;

	float m_fHangTime;

	float m_fBeginJumpTime;

	float m_fJumpSpeed;

	const float m_fAcceleration;

	D3DXVECTOR3 m_vecJumpPos;

	D3DXVECTOR3 m_vecSpeed;

	D3DXVECTOR3 m_vecPos;

	bool m_bInMoving;

	Locations m_Distination;

public:
	void SetDestination(Locations dest)
	{
		m_Distination = dest;
	}

// AI
private:
	StateMachine<Miner>* m_pStateMachine;

	Locations m_Location;

	std::list<POINTU> m_listRoute;

	float m_fGoldCarried;

	int m_iMoneyInBank;

	float m_fThirst;

	int m_iTargetAmount;

	float m_fLastUpdateTime;

public:
	Miner(int id);

	virtual ~Miner(void);

	virtual void Update(float fTime);

	Locations Location(void) const { return m_Location; }
	bool ChangeLocation(Locations location, float fTime);
	void AddToGoldCarried(float val);
	void IncreaseFatigue(void);
	bool PocketsFull(void);
	bool Thirsty(void);

	StateMachine<Miner>* GetFSM() { return m_pStateMachine; }
	void Sleep(void);
	void DepositGold(void);
	void SetTargetAmount(void);
	bool Reached(void);
	bool Drink(float fTime);
	bool Walking(float fTime);
};

#include "..\GWorld\GWorld.h"